/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package regex.demo;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.*;

/**
 *
 * @author VANDH
 */
public class regex {

    public static void main(String[] args) {
// Metacharacter : ()[]{}, \|., ?*+, ^-$
//        getGroupMatch("[^fc]oo", "wool fool cool");
        // Greedy -> tham ăn, tìm chuỗi dài nhất có thể
        //
        getGroupMatch("q.*?y$", "quyantity qyuestions create a quanlity answery");
//        String input = "Doublef the vowels.";
//        String regex = "[aeiou]+(f)";
//        String output = input.replaceAll(regex, "$0$0");
//        System.out.println(output);

//        String input = "The cat meows\nand meows and";
//        String regex = "\\bmeows\\z";
//
//        String output = Pattern.compile(regex, Pattern.MULTILINE).matcher(input).replaceAll("barks");
//        System.out.println(output);
//        Integer[] array = new Integer[]{1, 2, 3};
//        Arrays.sort(array, Collections.reverseOrder());
//        Double b = 1.5;
//        System.out.println(b);
//        for (Integer i : array) {
//            System.out.println(i.toString());
//        }
    }

    // source = "a", destionation="abc"
    public static void getGroupMatch(String source, String destination) {
        Pattern p = Pattern.compile(source);
        Matcher m = p.matcher(destination);

        while (m.find()) {
            System.out.println(m.group());
        }
    }
}
